//author: create by SunJH
//时间: 2021/12/15 0015
//邮箱: 965989158@qq.com
//描述: 极光推送获取页面的pop和push监听，用于统计app的使用情况

import 'package:flutter/cupertino.dart';
import 'package:flutter_app/utils/jg_util.dart';
import 'package:flutter_app/utils/log_util.dart';

class AnalySis extends NavigatorObserver {

  @override
  void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
    var popRouteName = route.settings.name ?? "";
    ///被出栈的页面
    if ((popRouteName).isNotEmpty) JGUtil.instance.getJAnalytics.onPageEnd(popRouteName);
  }

  @override
  void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
    var nowRouteName = route.settings.name ?? "";
    ///入栈页面路由
    if ((nowRouteName).isNotEmpty) JGUtil.instance.getJAnalytics.onPageStart(nowRouteName);
  }

  @override
  void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
    ///替换栈顶页面
    var oldPageName = oldRoute?.settings.name ?? "";
    var newPageName = newRoute?.settings.name ?? "";

    ///被replace的页面
    if ((oldPageName).isNotEmpty) JGUtil.instance.getJAnalytics.onPageEnd(oldPageName);

    ///入栈的页面
    if ((newPageName).isNotEmpty) JGUtil.instance.getJAnalytics.onPageStart(newPageName);
  }
}
